import {
  topupRecharge,
  getTopupList,
} from '../../services/order/api';

export default {
  namespace: 'expenseDetail',

  state: {

    loading: true,

    topupListData: {
      list: [],
      pagination:{}
    },

    rechargeRes: {}

  },

  effects: {

    *fetchTopupRecharge({payload,callback}, { call, put }) {
      const response = yield call(topupRecharge, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {rechargeRes: response.data}
        });
      }
      if (callback && response) callback(response);
    },

    *fetchGetTopupList({payload,callback}, { call, put }) {
      const response = yield call(getTopupList, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {
            topupListData: {
              list: response.data.records,
              pagination: {
                current: response.data.current,
                total: response.data.total,
                size: response.data.size,
              }
            }
          },
        });
      }
      if (callback && response) callback(response);
    },
    
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
